package com.xiguaji.tiktok.v1.tiktok.ranking.repository;

import com.xiguaji.tiktok.v1.tiktok.ranking.model.RankingFollowers;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RankingFollowersRepository extends CrudRepository<RankingFollowers,Long> , RankingFollowersExtRepository {

    /**
     * 获取最近周、月排行时间
     * @param rankingType
     * @return
     */
    @Query("SELECT IFNULL(MAX( update_time ),0)  FROM ranking_followers " +
            "WHERE belong = (select max(belong) from ranking_followers where ranking_type = :rankingType) and ranking_type = :rankingType ORDER BY update_time DESC ")
    long findUpdateTime(int rankingType);

    /**
     * 获取最近日排行时间
     * @param rankingType
     * @return
     */
    @Query("SELECT IFNULL(MAX( update_time ),0)  FROM ranking_followers " +
            "WHERE belong = (select max(belong) from ranking_followers) and ranking_type = :rankingType ORDER BY update_time DESC ")
    long findRkDayUpdateTime(int rankingType);

    @Query("select DISTINCT(belong) from ranking_followers where ranking_type = :rankingType and belong > :startDate ORDER BY belong DESC")
    List<Integer> findBelongDate(int rankingType, int startDate);
}
